<%@ page language="java" contentType="text/plain; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.sql.*"%>
[<%
 
 request.setCharacterEncoding("UTF-8");
 String keyword = request.getParameter("keyword");
 
 Connection conn = null;
 PreparedStatement pstmt = null;
 ResultSet rs = null;
 
 String jdbcUrl = "jdbc:oracle:thin:@192.168.0.33:1521:orcl2";
 String dbId = "scott";
 String dbPass = "tiger";
 String sql = "";
 
 
 try{
  Class.forName("oracle.jdbc.driver.OracleDriver");
  conn = DriverManager.getConnection(jdbcUrl,dbId,dbPass);
  System.out.println("keyword : "+keyword);
 	
  sql = "select * from zipcode where sido like ? or gugun like ? or dong like ? order by seq desc";
 		pstmt = conn.prepareStatement(sql);
  		pstmt.setString(1, "%"+keyword+"%");
  		pstmt.setString(2, "%"+keyword+"%");
  		pstmt.setString(3, "%"+keyword+"%");
  
  rs = pstmt.executeQuery();
  while(rs.next()){
				String zipcode = rs.getString("zipcode");
				String sido = rs.getString("sido");
				String gugun = rs.getString("gugun");
				String dong = rs.getString("dong");
				String bunji = rs.getString("bunji");
				
				if(rs.getRow()>1){
					out.print(",");
				}
				%>
				{
					"zipcode":"<%=zipcode %>",
					"sido":"<%=sido %>",
					"gugun":"<%=gugun %>",
					"dong":"<%=dong %>",
					"bunji":"<%=bunji %>"
				}
				<% 
  }
 
 }catch(Exception e){
  e.printStackTrace();
 }finally{
  if(rs != null)try{rs.close();}catch(SQLException e){}
  if(pstmt != null)try{pstmt.close();}catch(SQLException e){}
  if(conn != null)try{conn.close();}catch(SQLException e){}
 }
%>]